2000. 反转单词前缀
为保证权益,题目请参考 2000. 反转单词前缀(From LeetCode).
解决方案1
Python
python
# 2000. 反转单词前缀
# https://leetcode-cn.com/problems/reverse-prefix-of-word/
class Solution:
def reversePrefix(self, word: str, ch: str) -> str:
ch_index = word.find(ch)
if ch_index == -1:
return word
return word[:ch_index+1][::-1] + word[ch_index + 1:]
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10